f = open("./文件读写.py",'r')
s = f.read()
print(s)
f.close()


# 防止出现异常导致 f.close()无法调用
try:
    f = open("./文件读写.py","r")
    s = f.read()
    print(s)
finally:
    if f:
        f.close()
    
# try except的简洁写法：
with open('./文件读写.py', 'r') as f:
    print(f.read())
    for line in f.readlines():
        print(line.strip()) # 把末尾的'\n'删掉


